package cn.sf.sufingadminprovider.serviceImpl;

import cn.sf.pojo.User;
import cn.sf.service.UserManagerService;
import cn.sf.sufingadminprovider.dao.UserManagerMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserManagerServiceImpl implements UserManagerService {

  @Resource private UserManagerMapper userManagerMapper;

  @Override
  @RequestMapping("/selectAllUserInfo")
  public List<User> selectAllUserInfo() {
    System.out.println("查询1");
    return userManagerMapper.selectAllUserInfo();
  }

  @Override
  @RequestMapping("/selectById")
  public List<User> selectById(@RequestParam("userId") long userId) {
    System.out.println("依据用户Id进行查询");
    return userManagerMapper.selectById(userId);
  }

  @Override
  @RequestMapping("/selectByUserName")
  public List<User> selectByUserName(@RequestParam("userName") String userName) {
    System.out.println("用户名查询");
    return userManagerMapper.selectByUserName(userName);
  }

  @Override
  @RequestMapping("/selectByEmail")
  public List<User> selectByEmail(String userEmail) {
    return userManagerMapper.selectByEmail(userEmail);
  }

  @Override
  @RequestMapping("/selectByPhone")
  public List<User> selectByPhone(long userPhone) {
    return userManagerMapper.selectByPhone(userPhone);
  }

  @Override
  @RequestMapping("/selectBySex")
  public List<User> selectBySex(String userSex) {
    return userManagerMapper.selectBySex(userSex);
  }

  @Override
  @RequestMapping("/insertUserInfo")
  public int insertUserInfo(User user) {
    int result = userManagerMapper.insertUserInfo(user);
    if (result > 0) {
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  @RequestMapping("/UpdateUserInfo")
  public int UpdateUserInfo(User user) {
    int result = userManagerMapper.UpdateUserInfo(user);
    if (result > 0) {
      return 1;
    } else {
      return 0;
    }
  }

  @Override
  @RequestMapping("/deleteById")
  public int deleteById(long userId) {
    int result = userManagerMapper.deleteById(userId);
    if (result > 0) {
      return 1;
    } else {
      return 0;
    }
  }
}
